#include "createprojectdialog.h"
#include "ui_createprojectdialog.h"

CreateProjectDialog::CreateProjectDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CreateProjectDialog)
{
    ui->setupUi(this);
    ui->comboBox_type->addItems(QStringList()<<"LCD"<<"IDU");
}

CreateProjectDialog::~CreateProjectDialog()
{
    delete ui;
}

void CreateProjectDialog::on_pushButton_ok_clicked()
{
    QString path = ui->lineEdit_path->text();

    if (path == "")
    {
        QMessageBox::warning(this, QObject::tr("waring"), QObject::tr("please input path"));
        return;
    }
    accept();
}

void CreateProjectDialog::on_pushButton_cancel_clicked()
{
    reject();
}

ProjectData CreateProjectDialog::showAndGetResult()
{
    ProjectData pro_data = {"format", 1920, 1080, "", "LCD"};
    if (this->exec() == QDialog::Accepted)
    {
        QString path = ui->lineEdit_path->text();
        int width = ui->lineEdit_width->text().toInt();
        int height = ui->lineEdit_height->text().toInt();
        QString type = ui->comboBox_type->currentText();
        pro_data.width = width;
        pro_data.height = height;
        pro_data.path = path;
        pro_data.type = type;
        return pro_data;
    }
    return {"", 0, 0, "", "LCD"};
}

void CreateProjectDialog::on_pushButton_select_clicked()
{
    QString path = QFileDialog::getExistingDirectory(this);
    ui->lineEdit_path->setText(path);
}
